from datetime import date, datetime

from entity.mistake_details import Mistake_details
from entity.mistake_history import Mistake_history
from entity.user import User
from database.database import Database

class INIT:
    def __init__(self,uid,username):
        self.uid = uid
        self.username = username
        self.types_list = ['calculate', 'concept', 'reading', 'solving']
        self.details_list = [['algebra', 'sign', 'unit', 'number'], ['equation', 'format', 'forget'],
                             ['understand', 'repeat'],['incomplete', 'conclusion', 'guessing']]
        self.weights_list = [[7, 7, 8, 8], [19, 19, 19], [4, 4], [4, 4, 5]]


    def init_mistake_details(self):
        db = Database()

        # 创建学生对象并初始化
        new_user = User(self.uid,self.username,"seventh")
        db.insert_user(new_user)

        # 创建错误类型、错误细节并初始化
        # 创建一个列表来存储对象
        objects_list = []
        id = 0

        # 确保两个列表的长度一致
        if len(self.types_list) == len(self.details_list):
            for i in range(len(self.types_list)):
                type_val = self.types_list[i]
                details_val = self.details_list[i]
                values_val = self.weights_list[i]

                # 确保对应的details和values列表长度一致
                if len(details_val) == len(values_val):
                    for j in range(len(details_val)):
                        # 根据循环遍历赋值对象属性
                        id = id+1
                        obj = Mistake_details(id, self.uid, type_val, details_val[j], date.today(), 0, values_val[j])
                        objects_list.append(obj)
                        db.insert_mistake_details(obj)
                else:
                    print(f"Error: The lengths of details and values for {type_val} do not match.")
        else:
            print("Error: The lengths of types and details lists do not match.")

        for obj in objects_list:
            print(obj.id, obj.uid, obj.type, obj.details, obj.times, obj.weight, obj.latestDate)

        db.close_connection()

